#define  _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;

#include"SmartPtr.h"

void test_auto_ptr()
{
	lsg::auto_ptr<int> ap1(new int(1));
	lsg::auto_ptr<int> ap2(new int(2));
	lsg::auto_ptr<int> ap3(ap1);

	//*ap1 = 10;
	*ap2 = 20;
	ap2 = ap3;
}

void test_unique_ptr()
{
	lsg::unique_ptr<int> up1(new int(2));
	lsg::unique_ptr<int> up2(new int(22));
	
	/*lsg::unique_ptr<int> up3(up1);
	up2 = up1;*/
}

void test_shared_ptr()
{
	lsg::shared_ptr<int> sp1(new int(1));
	lsg::shared_ptr<int> sp2(new int(1));
	lsg::shared_ptr<int> sp3(new int(1));

	lsg::shared_ptr<int> sp4(sp1);
	sp3 = sp2;
}

struct Node
{
	lsg::weak_ptr<Node> _next;
	lsg::weak_ptr<Node> _prev;
};

void test_weak_ptr()
{
	lsg::shared_ptr<Node> sp1(new Node);
	lsg::shared_ptr<Node> sp2(new Node);

	cout << sp1.use_count() << endl;
	cout << sp2.use_count() << endl;

	sp1->_next = sp2;                    
	sp2->_prev = sp1;

	cout << sp1.use_count() << endl;
	cout << sp2.use_count() << endl;
}


int main()
{
	//test_auto_ptr();
	//test_unique_ptr();
	//test_shared_ptr();
	test_weak_ptr();

	return 0;
}